﻿@using OpenReservation.Models
@using OpenReservation.ViewModels
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<ReservationListViewModel> Localizer
@inject IStringLocalizer<SharedResource> SharedLocalizer
@model IPagedListModel<OpenReservation.ViewModels.ReservationListViewModel>
@{
    Layout = null;
}
@if (Model.Data != null && Model.Data.Count > 0)
{
    <table class="table table-hover">
        <thead>
            <tr>
                <th>@Localizer["ReservationPlaceName"]</th>
                <th>@Localizer["ReservationForDate"]</th>
                <th>@Localizer["ReservationForTime"]</th>
                <th>@Localizer["ReservationUnit"]</th>
                <th>@Localizer["ReservationActivityContent"]</th>
                <th>@Localizer["ReservationPersonName"]</th>
                <th>@Localizer["ReservationPersonPhone"]</th>
                <th>@Localizer["ReservationTime"]</th>
                <th>@Localizer["ReservationStatus"]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Data)
            {
                string status = @SharedLocalizer[$"ReservationStatus_{item.ReservationStatus}"], className = "";
                switch (item.ReservationStatus)
                {
                    case ReservationStatus.UnReviewed:
                        className = "";
                        break;
                    case ReservationStatus.Reviewed:
                        className = "bg-success";
                        break;
                    case ReservationStatus.Rejected:
                        className = "bg-danger";
                        break;
                    case ReservationStatus.Canceled:
                        className = "bg-warning";
                        break;
                    default:
                        break;
                }
                <tr class="@className">
                    <td>
                        @item.ReservationPlaceName
                    </td>
                    <td>
                        @item.ReservationForDate.ToString("yyyy-MM-dd")
                    </td>
                    <td>
                        @Html.Raw(item.ReservationForTime.Replace(",", "<br />"))
                    </td>
                    <td>
                        @item.ReservationUnit
                    </td>
                    <td>
                        @item.ReservationActivityContent
                    </td>
                    <td>
                        @item.ReservationPersonName
                    </td>
                    <td>
                        @item.ReservationPersonPhone
                    </td>
                    <td>
                        @item.ReservationTime.AddHours(8).ToString("yyyy-MM-dd HH:mm:ss")
                    </td>
                    <td>
                        @Html.Raw(status)
                    </td>
                    <td>
                        @if (item.ReservationStatus == ReservationStatus.Reviewed)
                        {
                            <button type="button" class="btn btn-default" onclick="view('@item.ReservationId', '@item.ReservationPersonPhone')">查看</button>
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
@Html.Pager(Model.Pager, pageIndex => $"javascript:loadData({pageIndex})", "PagerPartial", PagingDisplayMode.IfNeeded)